﻿
namespace bookMaster.AssetSystem.Windows.Forms
{
	/// <summary>
	/// abstract TiposRecursos typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class TiposRecursosDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<TiposRecursosDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities.TiposRecursos _currentTiposRecursos = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView uxTiposRecursosDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxTiposRecursosErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource uxTiposRecursosBindingSource;
		
		
		/// <summary> 
		/// the DGV column associated with the TipoRecurso property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxTipoRecursoDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the DescripcionTipoRecurso property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxDescripcionTipoRecursoDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Orden property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxOrdenDataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities.TiposRecursos> _TiposRecursosList;
				
		/// <summary> 
		/// The list of TiposRecursos to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities.TiposRecursos> TiposRecursosList
		{
			get {return this._TiposRecursosList;}
			set
			{
				this._TiposRecursosList = value;
				this.uxTiposRecursosBindingSource.DataSource = null;
				this.uxTiposRecursosBindingSource.DataSource = value;
				this.uxTiposRecursosDataGridView.DataSource = null;
				this.uxTiposRecursosDataGridView.DataSource = this.uxTiposRecursosBindingSource;				
				//this.uxTiposRecursosBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(uxTiposRecursosBindingSource_ListChanged);
				this.uxTiposRecursosBindingSource.CurrentItemChanged += new System.EventHandler(OnTiposRecursosBindingSourceCurrentItemChanged);
			}
		}
		
		private void OnTiposRecursosBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentTiposRecursos = uxTiposRecursosBindingSource.Current as Entities.TiposRecursos;
			
			if (_currentTiposRecursos != null)
			{
				_currentTiposRecursos.Validate();
			}
			//_TiposRecursos.Validate();
			OnCurrentEntityChanged();
		}

		//void uxTiposRecursosBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <c cref="Entities.TiposRecursos"/> instance.
		/// </summary>
		public Entities.TiposRecursos SelectedTiposRecursos
		{
			get {return this._currentTiposRecursos;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.uxTiposRecursosDataGridView.VirtualMode;}
			set
			{
				this.uxTiposRecursosDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.uxTiposRecursosDataGridView.AllowUserToAddRows;}
			set {this.uxTiposRecursosDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.uxTiposRecursosDataGridView.AllowUserToDeleteRows;}
			set {this.uxTiposRecursosDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <c cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.uxTiposRecursosDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.uxTiposRecursosDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="TiposRecursosDataGridViewBase"/> class.
		/// </summary>
		public TiposRecursosDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.uxTiposRecursosDataGridView = new System.Windows.Forms.DataGridView();
			this.uxTiposRecursosBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.uxTiposRecursosErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxTipoRecursoDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxDescripcionTipoRecursoDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxOrdenDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			((System.ComponentModel.ISupportInitialize)(this.uxTiposRecursosDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxTiposRecursosBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxTiposRecursosErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// uxTiposRecursosErrorProvider
			// 
			this.uxTiposRecursosErrorProvider.ContainerControl = this;
			this.uxTiposRecursosErrorProvider.DataSource = this.uxTiposRecursosBindingSource;						
			// 
			// uxTiposRecursosDataGridView
			// 
			this.uxTiposRecursosDataGridView.AutoGenerateColumns = false;
			this.uxTiposRecursosDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.uxTiposRecursosDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxTipoRecursoDataGridViewColumn,
		this.uxDescripcionTipoRecursoDataGridViewColumn,
		this.uxOrdenDataGridViewColumn			});
			this.uxTiposRecursosDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.uxTiposRecursosDataGridView.Location = new System.Drawing.Point(0, 0);
			this.uxTiposRecursosDataGridView.Name = "uxTiposRecursosDataGridView";
			this.uxTiposRecursosDataGridView.Size = new System.Drawing.Size(470, 300);
			this.uxTiposRecursosDataGridView.TabIndex = 0;	
			this.uxTiposRecursosDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.uxTiposRecursosDataGridView.EnableHeadersVisualStyles = false;
			this.uxTiposRecursosDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.OnTiposRecursosDataGridViewDataError);
			this.uxTiposRecursosDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnTiposRecursosDataGridViewCellValueNeeded);
			this.uxTiposRecursosDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnTiposRecursosDataGridViewCellValuePushed);
			
			//
			// uxTipoRecursoDataGridViewColumn
			//
			this.uxTipoRecursoDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxTipoRecursoDataGridViewColumn.DataPropertyName = "TipoRecurso";
			this.uxTipoRecursoDataGridViewColumn.HeaderText = "TipoRecurso";
			this.uxTipoRecursoDataGridViewColumn.Name = "uxTipoRecursoDataGridViewColumn";
			this.uxTipoRecursoDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxTipoRecursoDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxTipoRecursoDataGridViewColumn.ReadOnly = false;		
			//
			// uxDescripcionTipoRecursoDataGridViewColumn
			//
			this.uxDescripcionTipoRecursoDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxDescripcionTipoRecursoDataGridViewColumn.DataPropertyName = "DescripcionTipoRecurso";
			this.uxDescripcionTipoRecursoDataGridViewColumn.HeaderText = "DescripcionTipoRecurso";
			this.uxDescripcionTipoRecursoDataGridViewColumn.Name = "uxDescripcionTipoRecursoDataGridViewColumn";
			this.uxDescripcionTipoRecursoDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxDescripcionTipoRecursoDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxDescripcionTipoRecursoDataGridViewColumn.ReadOnly = false;		
			//
			// uxOrdenDataGridViewColumn
			//
			this.uxOrdenDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxOrdenDataGridViewColumn.DataPropertyName = "Orden";
			this.uxOrdenDataGridViewColumn.HeaderText = "Orden";
			this.uxOrdenDataGridViewColumn.Name = "uxOrdenDataGridViewColumn";
			this.uxOrdenDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxOrdenDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxOrdenDataGridViewColumn.ReadOnly = false;		
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.uxTiposRecursosDataGridView);
			this.Name = "TiposRecursosDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			((System.ComponentModel.ISupportInitialize)(this.uxTiposRecursosErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxTiposRecursosDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxTiposRecursosBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				TiposRecursosDataGridViewEventArgs args = new TiposRecursosDataGridViewEventArgs();
				args.TiposRecursos = _currentTiposRecursos;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class TiposRecursosDataGridViewEventArgs : System.EventArgs
		{
			private Entities.TiposRecursos	_TiposRecursos;
	
			/// <summary>
			/// the  Entities.TiposRecursos instance.
			/// </summary>
			public Entities.TiposRecursos TiposRecursos
			{
				get { return _TiposRecursos; }
				set { _TiposRecursos = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the uxTiposRecursosDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void OnTiposRecursosDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the uxTiposRecursosDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnTiposRecursosDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxTiposRecursosDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxTipoRecursoDataGridViewColumn":
						e.Value = TiposRecursosList[e.RowIndex].TipoRecurso;
						break;
					case "uxDescripcionTipoRecursoDataGridViewColumn":
						e.Value = TiposRecursosList[e.RowIndex].DescripcionTipoRecurso;
						break;
					case "uxOrdenDataGridViewColumn":
						e.Value = TiposRecursosList[e.RowIndex].Orden;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the uxTiposRecursosDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnTiposRecursosDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxTiposRecursosDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxTipoRecursoDataGridViewColumn":
						TiposRecursosList[e.RowIndex].TipoRecurso = (int)e.Value;
						break;
					case "uxDescripcionTipoRecursoDataGridViewColumn":
						TiposRecursosList[e.RowIndex].DescripcionTipoRecurso = (string)e.Value;
						break;
					case "uxOrdenDataGridViewColumn":
						TiposRecursosList[e.RowIndex].Orden = (System.Int32?)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
